package com.yangye.wechat.utils;

import com.yangye.wechat.entities.message.Music;
import com.yangye.wechat.entities.message.MusicMessage;
import com.yangye.wechat.entities.message.TextMessage;
import com.yangye.wechat.entities.repository.Cache;
import org.springframework.beans.BeanUtils;

import java.util.Date;
import java.util.Map;

public class MessageResponseUtil {

	/**
	 * 创建文本消息
	 * @param fromUserName
	 * @param toUserName
	 * @param content
	 * @return
	 */
	public static String createTextMessage(String fromUserName, String toUserName, String content) {
		TextMessage textMessage = new TextMessage();
		// 回复消息的时候发送方跟接收方反过来，不然会导致解析错误
		textMessage.setToUserName(fromUserName);
		textMessage.setFromUserName(toUserName);
		textMessage.setCreateTime(System.currentTimeMillis());
		textMessage.setMsgType(MessageUtil.RESP_MESSAGE_TYPE_TEXT);
		textMessage.setContent(content);
		return MessageUtil.textMessageToXml(textMessage);
	}

	/**
	 * 创建音乐消息
	 * @param fromUserName
	 * @param toUserName
	 * @return
	 */
	public static String createMusicMessage(String fromUserName, String toUserName, Music music){
		MusicMessage musicMessage = new MusicMessage();
		musicMessage.setToUserName(fromUserName);
		musicMessage.setFromUserName(toUserName);
		musicMessage.setCreateTime(new Date().getTime());
		musicMessage.setMsgType(MessageUtil.RESP_MESSAGE_TYPE_MUSIC);
		musicMessage.setMusic(music);
		return MessageUtil.musicMessageToXml(musicMessage);
	}

	public static void main(String[] args) {
		System.out.println(createTextMessage("from", "to", "你好"));
		System.out.println(createMusicMessage("from", "to", Cache.music));
	}
}
